const mysql = require('mysql2/promise');

async function checkTableStructure () {
  const connection = await mysql.createConnection({
    host: '43.143.253.188',
    port: 3306,
    user: 'nextjs',
    password: 'yEAiRE2jcxTyRBy5',
    database: 'nextjs',
    timezone: '+08:00'
  });

  try {
    console.log('🔍 检查map_areas表结构...\n');

    // 检查表结构
    const [columns] = await connection.execute('DESCRIBE map_areas');
    console.log('📋 表字段:');
    columns.forEach(col => {
      console.log(`  ${col.Field.padEnd(15)} | ${col.Type.padEnd(20)} | ${col.Null} | ${col.Key} | ${col.Default || 'NULL'}`);
    });

    // 检查数据
    const [count] = await connection.execute('SELECT COUNT(*) as total FROM map_areas');
    console.log(`\n📊 总记录数: ${count[0].total}`);

    // 检查新字段是否有数据
    const [sample] = await connection.execute('SELECT id, name, parent_id, extension FROM map_areas LIMIT 10');
    console.log('\n📋 数据示例:');
    sample.forEach(row => {
      console.log(`  ID: ${row.id.toString().padStart(4)} | ${row.name.padEnd(20)} | 父级ID: ${(row.parent_id || 'NULL').toString().padStart(8)} | 扩展: ${row.extension || 'NULL'}`);
    });

  } catch (error) {
    console.error('❌ 检查失败:', error.message);
  } finally {
    await connection.end();
  }
}

checkTableStructure(); 